package com.aceitunaproject.client;

import com.aceitunaproject.shared.gamelement.GameElement;
import com.aceitunaproject.shared.gamelement.Installation;
import com.aceitunaproject.shared.gamelement.Settlement;
import com.aceitunaproject.shared.gamelement.Unit;

/**
 * A wrapper for the game element classes, providing methods ands properties
 * useful to the UI
 * 
 * @author Federico Bergstein
 * 
 */
public class ElementWrapper {

	private GameElement gameElement;
	private EnumGameElementType elementType;

	public ElementWrapper(GameElement element,EnumGameElementType type)
	{
		this.gameElement = element;
		this.elementType = type;
	}
	
	public EnumGameElementType getType(){
		return this.elementType;
	}
	
	public Unit getAsUnit()
	{
		return (Unit)gameElement;
	}
	public Installation getAsInstallation()
	{
		return (Installation)gameElement;
	}
	public Settlement getAsSettlement()
	{
		return (Settlement)gameElement;	
	}
	
	public String toString()
	{
		String result = gameElement.getName() + " (" + gameElement.getPlayer().getName() + ")";
		
		if(elementType == EnumGameElementType.Settlement)
		{
			result += "(" + getAsSettlement().getPersons() + ")";
		}
		
		return result;
	}

	public Long getId() {
		return gameElement.getId();
	}
}
